<?php
	require(__META_CONTROLS_GEN__ . '/SampleMetaControlGen.class.php');

	/**
	 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality of the
	 * Sample class.  This code-generated class extends from
	 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
	 * display an HTML form that can manipulate a single Sample object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a SampleMetaControl
	 * class.
	 *
	 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
	 * or overwrite this file.
	 * 
	 * @package My QCubed Application
	 * @subpackage MetaControls
	 */
	class SampleMetaControl extends SampleMetaControlGen {

                private $dttTime;
                private $txtaOrg;
		// Initialize fields with default values from database definition
/*		
		public function __construct($objParentObject, Sample $objSample) {
			parent::__construct($objParentObject,$objSample);
			if ( !$this->blnEditMode ){
				$this->objSample->Initialize();
			}
		}
*/
                public function txtaOrg_Create($strControlId = null) {
			$this->txtaOrg = new QAjaxAutoCompleteTextBox($this->objParentObject, 'txtaOrg_Change',$strControlId);
                        $this->txtaOrg->Name = QApplication::Translate('Organization');
                        $this->txtaOrg->MustMatch=true;
                        $this->txtaOrg->Required = true;
                        if($this->objSample->OrgId) $this->txtaOrg->Text = $this->objSample->Org->__toString();
			$this->txtaOrg->MaxLength = Org::NameMaxLength;
			return $this->txtaOrg;
		}


                public function calDate_Create($strControlId = null) {
			$this->calDate = new QCalendarPopup($this->objParentObject, $strControlId);
			$this->calDate->Name = QApplication::Translate('Date');
			
			//$this->calDate->DateTimePickerType = QDateTimePickerType::Date;
                        if ($this->blnEditMode)
                            $this->calDate->DateTime = $this->objSample->Date;
                        else{ //new
                            $DefualtDate = new QDateTime();
                            $DefualtDate->SetDate(date("Y"), date("m"), date("d"));
                            $this->calDate->DateTime= $DefualtDate;
                        }

			return $this->calDate;
		}

                public function SaveSample() {
			try {
                               
                                if (strlen($this->txtaOrg->Text) > 0){
                                        $objOrg=Org::LoadByName($this->txtaOrg->Text);
                                        $this->objSample->OrgId  = $objOrg->Id;
                                }
                                
                                
                                $this->dttTime = new QDateTime();
                                $this->dttTime->setDate (date("Y"), date("m"), date("d"));
                                $this->dttTime->setTime (date("H"), date("i"), date("s"));

                                $CurrentUser = $_SESSION['User']['Id'];
                                //should change user
                                $Euser       = $_SESSION['User']['Id'];
				$this->objSample->Euser = $Euser;
                                // Update any fields for controls that have been created
				
				if ($this->chkReturnable) $this->objSample->Returnable = $this->chkReturnable->Checked;
				if ($this->calDate) $this->objSample->Date = $this->calDate->DateTime;
				if ($this->blnEditMode){
                                        //Updating
                                        $this->objSample->UpdateBy   = $CurrentUser;
                                        $this->objSample->UpdateDate = $this->dttTime;
                                }
                                else{
                                        //New
                                        $this->objSample->CreateBy   = $CurrentUser;
                                        $this->objSample->CreateDate = $this->dttTime;
                                }
				// Update any UniqueReverseReferences (if any) for controls that have been created for it
				$this->objSample->Save();
				// Finally, update any ManyToManyReferences (if any)
				$this->lstPeopleAsReceiving_Update();
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>